<!DOCTYPE html>  
<html lang="en">  
<head>  
<meta charset="UTF-8">  
<meta name="viewport" content="width=device-width, initial-scale=1.0">  
<title>Pause/Resume Example</title>  
<script>  
document.addEventListener('DOMContentLoaded', function() {  
    let isPaused = true; // 初始状态为暂停  
    let counter = 0;  
    let intervalId;  
  
    function startOrPause() {  
        if (isPaused) {  
            // 开始执行  
            intervalId = setInterval(function() {  
                if (!isPaused) {  
                    counter++;  
                    document.getElementById('counter').textContent = counter;  
                }  
            }, 1000); // 每秒更新一次计数器  
            isPaused = false; // 设置为非暂停状态  
            document.getElementById('button').textContent = '暂停';  
        } else {  
            // 暂停执行  
            clearInterval(intervalId); // 清除定时器  
            isPaused = true; // 设置为暂停状态  
            document.getElementById('button').textContent = '开始';  
        }  
    }  
  
    // 绑定按钮点击事件  
    document.getElementById('button').addEventListener('click', startOrPause);  


    let flag = true;
let id;
function pause(){
    if(flag){
        flag = false;
        id= setInterval(function(){},1000)
    }else{
        clearInterval(id)
        flag=true
    }
    
}
document.querySelector("#sss").addEventListener("click",pause)

});  


</script>  
</head>  
<body>  
<button id="button">开始</button>  
<p>计数器: <span id="counter">0</span></p>  
<button id="sss">第二个</button>
</body>  
</html>